<script>
	import * as loginServer from '@/common/login.js';
	import * as api from '@/common/api.js';
	import config from '@/config.js';


	let firstload = false
	export default {
		onLaunch: function() {
			console.log('App Launch');
			firstload = true
			this.globalData.baseUrl = config.baseUrl;
			this.globalData.baseUrl_api = config.baseUrl_api;
			this.globalData.fileUrl = config.fileUrl;

			new Promise((resolve, reject) => {
					uni.checkSession({
						success: res => {
							console.log('checkSession',res)
							loginServer.pcLogin()
							// loginServer
							// 	.getCurrUser(true)
							// 	.catch(() => { 
							// 		return loginServer.pcLogin();
							// 	})
							// 	.then(user => {
							// 		resolve(user);
							// 	});
						},
						fail: res => {
							loginServer
								.wxLogin()
								.then(loginRes => {
									return loginServer.pcLogin(loginRes.code);
								})
								.then(user => {
									resolve(user);
								});
						}
					});
				})
				.then(()=>{
					return loginServer.getNowOpenId()
				})
				.then(() => {
					return loginServer.initData()
					// console.log(22222222)
					// const currUser = uni.getStorageSync('currUser');
					// // console.log(currUser)
					// return Promise.all([api.getVenue(), api.getOwnMemberInfo()]).then(res => {
					// 	let ven = res[0].data;
					// 	let men = res[1]?.data;

					// 	if (ven.venuePic) {
					// 		ven.venuePicArr = ven.venuePic.split(',');
					// 	}
					// 	if (ven.businessPeriod) {
					// 		ven.startBus = ven.businessPeriod.split(',')[0];
					// 		ven.endBus = ven.businessPeriod.split(',')[1];
					// 	}
					// 	ven.latitude = ven.lal.split(',')[0];
					// 	ven.longitude = ven.lal.split(',')[1];

					// 	this.globalData.venue = ven;
					// 	this.globalData.isVip = men?.isVip;
					// 	// this.globalData.relateProjectId = men.info.relateProjectId;
					// 	this.globalData.relateProjectIdList = men?.info?.relateProjectIdList;
					// 	this.globalData.relateVenueProjectIdList = men?.info?.relateVenueProjectIdList;

					// 	this.globalData.venueConfig = {
					// 		normalOverDay: ven.resSiteConfig?.normalOrderNum,
					// 		normalPeriodStart: ven.resSiteConfig?.normalOrderPeriod.split(',')[0],
					// 		normalPeriodEnd: ven.resSiteConfig?.normalOrderPeriod.split(',')[1]
					// 	};
					// 	if (men?.isVip) {
					// 		this.globalData.venueConfig.memberOverDay = ven.resSiteConfig?.memberOrderNum;
					// 		this.globalData.venueConfig.memberPeriodStart = ven.resSiteConfig?.memberOrderPeriod.split(',')[0];
					// 		this.globalData.venueConfig.memberPeriodEnd = ven.resSiteConfig?.memberOrderPeriod.split(',')[1];
					// 	}
					// });
				})
				.then(() => {
					this.globalData.isLogin = true;
					let firstLoadCallback = getApp().firstLoadCallback;
					if (firstLoadCallback) {
						firstLoadCallback();
					}
				});
		},
		onShow: function() {
			console.log('App Show');
			// loginServer.getNowOpenId()
			if (!firstload) {
				loginServer.getCurrUser(true)
					.catch(() => {
						return loginServer.pcLogin().then(() => {
							uni.redirectTo({
								url: getCurrentPages()[getCurrentPages().length - 1].$page.fullPath
							})
						});
					})
			} 
		},
		onHide: function() {
			console.log('App Hide');
		}
	};
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '/common/uni.css';
	@import '/common/mystyle.scss';
	@import '@/static/font/iconfont.css';
</style>